-- @owner:yangjian
-- @date:2024-7-1
-- @testpoint:1.去除大对象使用限制，测试将大对象数据在表中vacuum，合理报错


--清理环境
CREATE OR REPLACE FUNCTION f_opengauss_large_object_vacuum_case0001_1()  
RETURNS VOID AS 
$$
BEGIN  
    BEGIN
    PERFORM lo_unlink(100);
    EXCEPTION
        WHEN others THEN
            NULL;
    end;
    BEGIN
    PERFORM lo_unlink(101);
    EXCEPTION
        WHEN others THEN
            NULL;
    end;
END;  
$$
LANGUAGE plpgsql;
/

select f_opengauss_large_object_vacuum_case0001_1();

--环境准备
drop table if exists t_opengauss_large_object_vacuum_case0001_1 cascade;
drop table if exists t_opengauss_large_object_vacuum_case0001_2 cascade;
CREATE TABLE t_opengauss_large_object_vacuum_case0001_1 (loid oid,fd int);
INSERT INTO t_opengauss_large_object_vacuum_case0001_1 (loid) SELECT lo_create(100);
CREATE TABLE t_opengauss_large_object_vacuum_case0001_2 (a text);

--step1:使用lo_get函数将大对象插入表中;expect:成功
select lo_put(100,6,'aaaaaa');
insert into t_opengauss_large_object_vacuum_case0001_2 select lo_get(100,6,6);
select * from t_opengauss_large_object_vacuum_case0001_2;

vacuum full t_opengauss_large_object_vacuum_case0001_2;

select * from t_opengauss_large_object_vacuum_case0001_2;

--step2:使用loread函数将大对象插入表中;expect:成功
INSERT INTO t_opengauss_large_object_vacuum_case0001_1 (loid) SELECT lo_create(101);
begin;
SELECT lo_open(101,CAST(x'20000' | x'40000' AS integer));
select lowrite (0,'aaaaaaaaaa');
insert into t_opengauss_large_object_vacuum_case0001_2 select loread (0, 6);
end;
/
select * from t_opengauss_large_object_vacuum_case0001_1;

vacuum full t_opengauss_large_object_vacuum_case0001_1;

select * from t_opengauss_large_object_vacuum_case0001_1;

--清理环境
select lo_unlink(loid) from t_opengauss_large_object_vacuum_case0001_1;
select f_opengauss_large_object_vacuum_case0001_1();
drop table if exists t_opengauss_large_object_vacuum_case0001_1 cascade;
drop table if exists t_opengauss_large_object_vacuum_case0001_2 cascade;
drop function f_opengauss_large_object_vacuum_case0001_1();

